<?php
//****************************************************
// JTBC CMS Power by Jetiben.com
// Email: jetiben@hotmail.com
// Web: http://www.jtbc.net.cn/
//****************************************************
function get_sorts() {
	global $db, $sort_database, $ngenre;
	
	$db->sqlcmd = "select * from $sort_database where sort_genre='$ngenre' order by sort_order";
	return $db->execute_reader ();
}
function jtbc_cms_module_list() {
	global $conn, $nlng, $ngenre;
	global $sort_database, $sort_idfield;
	$tclassid = ii_get_num ( $_GET ['classid'] );
	$toffset = ii_get_num ( $_GET ['offset'] );
	global $nclstype, $nlisttopx, $npagesize;
	global $ndatabase, $nidfield, $nfpre;
	global $db;
	$db->sqlcmd = "select * from $sort_database where sort_genre='$ngenre'";
	$sorts = $db->execute_reader ();
	$result = array ();
	foreach ( $sorts as $sort ) {
		$sql = "select * from $ndatabase where " . ii_cfname ( 'class' ) . "='" . $sort ['sortid'] . "'";
		$db->sqlcmd = $sql;
		$data = $db->execute_reader ();
		$result[]=array("sort"=>$sort,"data"=>$data);
	}
	 
	//include 'common/template/index.php';
	include View ( "index" );
}

function jtbc_cms_module_detail() {
	global $conn, $ngenre;
	$tid = ii_get_num ( $_GET ['id'] );
	$tpage = ii_get_num ( $_GET ['page'] );
	global $ndatabase, $nidfield, $nfpre;
	$sql = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0 and $nidfield=$tid";
	$trs = ii_conn_query ( $sql, $conn );
	$trs = ii_conn_fetch_array ( $trs );
	if ($trs) {
		$tmpstr = ii_itake ( 'module.detail', 'tpl' );
		mm_cntitle ( ii_htmlencode ( $trs [ii_cfname ( 'topic' )] ) );
		foreach ( $trs as $key => $val ) {
			$tkey = ii_get_lrstr ( $key, '_', 'rightr' );
			$GLOBALS ['RS_' . $tkey] = $val;
			$tmpstr = str_replace ( '{$' . $tkey . '}', ii_htmlencode ( $val ), $tmpstr );
		}
		$tmpstr = str_replace ( '{$id}', $trs [$nidfield], $tmpstr );
		$tmpstr = str_replace ( '{$genre}', $ngenre, $tmpstr );
		$tmpstr = str_replace ( '{$page}', $tpage, $tmpstr );
		$tmpstr = ii_creplace ( $tmpstr );
		return $tmpstr;
	}
}

function jtbc_cms_module_index() {
	global $db, $ndatabase, $sort_idfield;
	
	$sorts = get_sorts ();
	
	$result = array ();
	foreach ( $sorts as $sort ) {
		$sql = "select * from $ndatabase where " . ii_cfname ( 'class' ) . "='" . $sort [$sort_idfield] . "'";
		$db->sqlcmd = $sql;
		$data = $db->execute_reader ();
		$result [] = array ("sort" => $sort, "data" => $data );
	}
	
	include View ( "index" );
}

function jtbc_cms_module() {
	switch ($_GET ['type']) {
		case 'list' :
			return jtbc_cms_module_list ();
			break;
		case 'detail' :
			return jtbc_cms_module_detail ();
			break;
		case 'index' :
			return jtbc_cms_module_index ();
			break;
		default :
			return jtbc_cms_module_index ();
			break;
	}
}
//****************************************************
// JTBC CMS Power by Jetiben.com
// Email: jetiben@hotmail.com
// Web: http://www.jtbc.net.cn/
//****************************************************
?>
